package edu.ustb.efws.pipeline.collect.handler;

import java.util.List;

/**
 * 责任链chain
 *
 * @author TS Group
 */
public class PipelineChain {
    private int pos = 0;
    private final List<PipelineHandler> handlers;

    public PipelineChain(List<PipelineHandler> handlers){
        this.handlers = handlers;
    }

    /**
     * 数据处理
     *
     * @param data 处理数据
     */
    public void doHandle(Object data) {
        if(pos == handlers.size()){
            return ;
        }

        handlers.get(pos++).handle(data, this);
    }

    @Override
    @SuppressWarnings("all")
    public PipelineChain clone(){
        return new PipelineChain(handlers);
    }
}
